package com.alcatel_lucent.osp.model;

import org.apache.struts2.json.annotations.JSON;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Collection;

@SuppressWarnings("serial")

@Entity
@Table(name = "USER")
public class User implements Serializable {

    private String csl;
    private String cil;
    private String email;
    private Timestamp createTime;
    private Timestamp lastLoginTime;
    private boolean active = true;
    private boolean superUser = false;

    private Collection<Category> categories;

    public User() {
    }

    public User(String csl, String email, String cil) {
        this.csl = csl;
        this.email = email;
        this.cil = cil;
    }

    @ManyToMany
    @JoinTable(name = "CATEGORY_USER",
            joinColumns = @JoinColumn(name = "USER_CSL"),
            inverseJoinColumns = @JoinColumn(name = "CATEGORY_ID")
    )
    public Collection<Category> getCategories() {
        return categories;
    }

    public void setCategories(Collection<Category> categories) {
        this.categories = categories;
    }

    @Id
    @Column(name = "CSL")
    public String getCsl() {
        return csl;
    }

    @Column(name = "SUPER_USER")
    public boolean isSuperUser() {
        return superUser;
    }

    public void setSuperUser(boolean superUser) {
        this.superUser = superUser;
    }

    public void setCsl(String csl) {
        this.csl = csl;
    }

    @Column(name = "CIL", nullable = false)
    public String getCil() {
        return cil;
    }

    public void setCil(String cil) {
        this.cil = cil;
    }

    @Column(name = "EMAIL", nullable = false)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @JSON(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "CREATE_TIME")
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @JSON(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "LAST_LOGIN_TIME")
    public Timestamp getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Timestamp lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    @Column(name = "ACTIVE", nullable = false)
    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @Override
    public String toString() {
        return "User{" +
                ", csl='" + csl + '\'' +
                ", cil='" + cil + '\'' +
                ", email='" + email + '\'' +
                ", categories=" + categories +
                '}';
    }
}
